<%@page import="com.shuohe.entity.system.user.User"%>
<%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8"%>
<%@ page language="java" import="java.util.*"%>

<%@ page import="com.shuohe.util.json.*" %>

<%@ page import="java.io.PrintWriter"%> 
<%
    String path = request.getContextPath();
    String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path;
    PrintWriter ss = response.getWriter();
    User user = null;
    String userStr = null;
    String pid = request.getParameter("pid");
    try
    {

        user = (User)session.getAttribute("user");
        if(user == null)
        {
            System.out.println("user = null");
            //response.sendRedirect(basePath+"/pages/login.jsp");
            String topLocation = "<script>top.location.href=\""+basePath+"/pages/login.jsp\"</script>";
            ss.print(topLocation);
        }
        userStr = Json.toJsonByPretty(user);
    }
        catch(Exception e)
    {
        String topLocation = "<script>top.location.href=\""+basePath+"/pages/login.jsp\"</script>";
        ss.print(topLocation);
        e.printStackTrace();
    }  
%>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>个人任务管理列表</title>


    <link type="text/css" href="/TopJUI/topjui/css/topjui.core.min.css" rel="stylesheet">
    <link type="text/css" href="/TopJUI/topjui/themes/default/topjui.green.css" rel="stylesheet" id="dynamicTheme"/>
    <!-- FontAwesome字体图标 -->
    <link type="text/css" href="/TopJUI/topjui/plugins/font-awesome/css/font-awesome.min.css" rel="stylesheet"/>
    <!-- jQuery相关引用 -->
    <script type="text/javascript" src="/TopJUI/topjui/plugins/jquery/jquery.min.js"></script>
    <script type="text/javascript" src="/TopJUI/topjui/plugins/jquery/jquery.cookie.js"></script>
    <!-- TopJUI框架配置 -->
    <script type="text/javascript" src="/TopJUI/static/public/js/topjui.config.js"></script>
    <!-- TopJUI框架核心-->
    <script type="text/javascript" src="/TopJUI/topjui/js/topjui.core.min.js"></script>
    <!-- TopJUI中文支持 -->
    <script type="text/javascript" src="/TopJUI/topjui/js/locale/topjui.lang.zh_CN.js"></script>

    <script type="text/javascript" src="/pages/js/moment.min.js"></script>
    <script type="text/javascript" src="/pages/js/layer/layer.js"></script>
    <script type="text/javascript" src="/pages/js/util.js"></script>

    <script type="text/javascript" src="/pages/js/base-loading.js"></script>
    <script type="text/javascript" src="/pages/js/shuoheUtil.js"></script>

    <style type="text/css">
        html, body{ margin:0; height:100%; }
    </style>

</head>
<body class="easyui-layout">

  <!--   <div data-options="region:'west',iconCls:'icon-reload',title:'',split:true" style="width:15%;">           
        <table id="tt" style="height:100%;width: 100%;" title="" data-options="
                  idField:'id',
                  treeField:'project_name',
                  method:'get'
                ">
          <thead>
              <tr>
                  <th field="project_name" width="100%">职位</th>
                  <th field="id" width="0px" hidden="true">序列</th>
              </tr>
          </thead>
        </table>        
    </div> -->

    <div data-options="region:'center',iconCls:'icon-reload',title:'',split:true" style="width:100%;height: 100%">
        <table id="dg" class='easyui-datagrid' style="width:98%;height:99% " title="" data-options="
                  rownumbers:false,
                  singleSelect:true,
                  autoRowHeight:false,
                  pagination:true,
                  fitColumns:false,
                  striped:true,
                  checkOnSelect:true,
                  selectOnCheck:true,
                  collapsible:false, 
                  toolbar:'#tb',
                  pageSize:20">
            <thead>
              <tr href="#">
                    <th data-options="field:'ck',checkbox:true"></th>
                    <th field="id" align="center" hidden ="true">id</th>
                    <th field="project_id" hidden="true">项目id</th>
                    <th field="projectNo" align="center" width="10%">项目编号</th>
                    <th field="project_name" width="10%">项目名称</th>
                    <th field="plan_name" width="17%" formatter='Easyui.Datagraid.formatterChinese'>任务内容</th>
                    <th field="difficulty_level" width="5%">难度等级</th>
                    <th field="actual_name" width="5%">执行者</th>
                    <th field="start_date" width="7%">开始日期</th>
                    <th field="deadline" width="7%">截止日期</th>
                    <th field="task_status" width="5%" formatter="formatterperFinishStatus">是否完成</th>
                    <th field="finish_time" width="10%">完成时间</th>
                    <th field="finish_situation" width="5%">完成情况</th>
                    <th field="estimate_coefficient" width="5%">评估系数</th>
                    <th field="performance_status" width="8%" formatter="formatterperFormance">是否结算绩效</th>
                    <th field="task_files" width="5%" formatter="formatterperFile">附件</th>
              </tr>
            </thead>
          </table>
          <div id="tb" style="height:35px">            
            <a id='btnInsert' href="javascript:void(0)" class="easyui-linkbutton" data-options="iconCls:'fa fa-check',plain:true" onclick="finish()" style="margin-left:5px">任务反馈</a>
            <a id='btnInsert' href="javascript:void(0)" class="easyui-linkbutton" data-options="iconCls:'fa fa-hand-pointer-o',plain:true" onclick="view()">查看</a>            
            <form id="queryForm" class="search-box">
                  <input class="easyui-combobox" id='query_task_status' data-options="prompt:'完成状态'">
                  <input class="easyui-combobox" id='query_count_status' data-options="prompt:'结算状态'">
                  <a id='btnQuery' href="#" class="easyui-linkbutton" btnCls='topjui-btn-normal' plain="true" iconCls="fa fa-search" onclick="functionQuery()" style="margin-left: 0px">搜索</a>          
                  <a id='btnClear' href="#" class="easyui-linkbutton" btnCls='topjui-btn-normal' plain="true" iconCls="fa fa-refresh" onclick="functionClear()" style="margin-left: 0px">清除</a>  
            </form>            
          </div>
       </div>
     <div id="dlg_img" class="easyui-dialog" title="附件列表" data-options="iconCls:'icon-save',closed:true" style="width:600px;height:400px;padding:10px">
<!--        <ul id="imgShow"></ul> -->
       <table id="dg_file" class='easyui-datagrid' style="width:98%;height:99% " title="" data-options="
                  rownumbers:false,
                  singleSelect:true,
                  autoRowHeight:false,
                  pagination:true,
                  fitColumns:false,
                  striped:true,
                  checkOnSelect:true,
                  selectOnCheck:true,
                  collapsible:false, 
                  toolbar:'#tb',
                  pageSize:20">
            <thead>
              <tr href="#">
                    <th data-options="field:'ck',checkbox:false"></th>
                    <th field="id" align="center" hidden ="true">id</th>
                    <th field="file_name" align="center" width="25%">文件名称</th>
                    <th field="upload_time" width="30%">上传时间</th>
                    <th field="actual_name" width="20%">上传人</th>
                    <th field="handle" width="25%" formatter="downloadFile">操作</th>
              </tr>
            </thead>
          </table>
	 </div>



  <script type="text/javascript">
    var project = new Object();
    var user = <%=userStr%>;
    var taskData = [{"id": "finish","text":"已完成"},{"id": "nofinish","text":"未完成"}];
    var countData = [{"id": "NOFINISH","text":"未计算"},{"id": "FINISH","text":"已计算"}];
    $(function(){
    	initSelect();
    	$('#dg').datagrid({
             nowrap:false                   
            });
        $.ajax({
            url: '/system/user/getUser.do',
            success: function(data) {
            	loadDg();                          
            }
        });
    });
    
    function loadDg(){
    	$('#dg').datagrid({
            url: '/develop/url/getUrl.do',
            queryParams: {
                name: 'getTaskList',
                'userId':user.id,
                'taskStatus':$('#query_task_status').combobox('getValue'),
                'count_status':$('#query_count_status').combobox('getValue')
            },
            method: 'get',
            onDblClickCell:function(index,field,value){
                //view();
            }
        }) 
    }

    var formateStatus = function(val,row)
    {
        if(row.is_finish == true && row.finish_date > row.plan_end_date)
            return '<font color="orange"><i class="fa fa-calendar-times-o"></i>延迟</font>';     
        if(row.is_finish == true)
            return '<font color="green"><i class="fa fa-calendar-check-o"></i>准时</font>';     
        // if(row.is_finish == false && !shuoheUtil.checkNull(row.finish_date))
        //     return '<font color="red"><i class="fa fa-calendar-times-o text-danger"></i></font>';

    }
    var formateDate = function(val,row)
    {
        if(row.is_finish == false)
            return moment(row.plan_end_date).diff(moment(), 'days')        
    }
    function finish()
    {
        var row = $('#dg').datagrid('getSelected');
        if(row == null)
        {
          layerMsgCustom('必须选择一条数据');
          return;
        }
        if(row.task_status=='finish'){
        	layerMsgCustom('该任务已经反馈，请检测');
            return;
        }
        layer.open({
            type: 2,
            title: '任务反馈',
            shadeClose: false,
            shade: 0.3,
            btn: '保存',
            maxmin: true, //开启最大化最小化按钮
            area: ['500px','400px'],
            content: 'form/editPersonalTask.jsp?masterplan_id=' + row.id,
            yes: function(index) {
                var ifname = "layui-layer-iframe" + index //获得layer层的名字
                var Ifame = window.frames[ifname] //得到框架
                Ifame.save();
            }
        })
    }
    
    function formatterperFile(value,row,index){
    	var btn = "";
        btn = '<a class="editcls" onclick="showImages(\''+ row.id+'\')" href="javascript:void(0)">查看</a>';
        return btn;
    }
    //文件下载
    function downloadFile(value,row,index){
    	ret =  '<a href="/pm2/project/downloadFile.do?fileRealPath='+row.file_real_path+'" class="easyui-linkbutton">下载</a>';   
        return ret;  
    }
    
    function showImages(id){
    	//var strImage="";
    	//$("#imgShow").html("");
    	$.ajax({
            url: "/pm2/project/getAllFileByTaskId.do",
            type: "POST",
            dataType: 'json',
            data: {
                'taskId': id
            },
            error: function() //失败
            {
                shuoheUtil.layerTopMaskOff();
            },
            success: function(data) //成功
            {   console.log(JSON.stringify(data));
            	/*
            	if(data.length==0){
            		strImage += '<li><font color="red" size="20">没有图片，请先上传</font></li>'
            	}
                for(var i=0;i<data.length;i++){
                	strImage += '<li><img alt="" src="'+data[i].filePath+'" style="margin-left: 25px;margin-bottom:15px;"></li>'
                       
                }
                $("#imgShow").append(strImage);*/
                $('#dg_file').datagrid('loadData',data);
                $("#dlg_img").dialog('open');
                
            }
        });
    }
	</script>




</body>
</html>
<script type="text/javascript">
    function add() {
      layer.open({
          type: 2,
          title: '新增设备',
          shadeClose: false,
          shade: 0.3,
          maxmin: true, //开启最大化最小化按钮s
          area: ['800px','500px'],
          content: 'form/addPlan.jsp?id='+project.id
      })
    }
  function view()
  {
      var row = $('#dg').datagrid('getSelected');
        if(row == null)
        {
          layerMsgCustom('必须选择一条数据');
          return;
        }

        layer.open({
            type: 2,
            // title: '查看详情',
            shadeClose: true,
            shade: 0.3,
            // maxmin: true, //开启最大化最小化按钮
            area: ['800px', (document.body.clientHeight - 100)+'px'],
            content: 'form/viewTask.jsp?taskId='+row.id
        })
  }

    function edit() {

        var row = $('#dg').datagrid('getSelected');
        if (row == null) {
            layerMsgCustom('必须选择一条数据');
            return;
        }

        layer.open({
            type: 2,
            title: '修改设备',
            shadeClose: false,
            shade: 0.3,
            maxmin: true, //开启最大化最小化按钮
            area: ['800px','400px'],
            content: 'form/editPlan.jsp?id=' + row.id+'&project_id='+ project.id
        })
    }
    function dele() {
        var row = $('#dg').datagrid('getSelected');
        if (row == null) {
            layerMsgCustom('必须选择一条数据');
            return;
        }
        //删除操作属于危险操作，给出提示
        $.messager.confirm('友情提示', '您确定要删除这条数据吗?', function(r) {
            if (r) {
                shuoheUtil.layerTopMaskOn();
                $.ajax({
                    url: "/mro/equipment/equipment/delete.do",
                    type: "POST",
                    dataType: 'json',
                    data: {
                        'id': row.id
                    },
                    error: function() //失败
                    {
                        shuoheUtil.layerTopMaskOff();
                    },
                    success: function(data) //成功
                    {
                        updateSuccess();
                        shuoheUtil.layerTopMaskOff();
                        if(data.result)
                        {
                            shuoheUtil.layerMsgOK(data.describe);
                        }
                        else
                        {
                            shuoheUtil.layerMsgError(data.describe);
                        }
                    }
                });
            }
        });
    }


  function updateSuccess()
  {
    $('#dg').datagrid('reload');

  }
  
  
  function functionQuery() {
	    loadDg();
	  }
	  function functionClear() {
		  $('#query_task_status').combobox('clear');
		    $('#query_count_status').combobox('clear');
	    loadDg();
	  }

  function formatterperFormance(value,row,index){
	  var reVal;
	  if(value=='NOFINISH'){
		  reVal="未结算";
	  }else if(value=='FINISH'){
		  reVal="已计算";
	  }else{
		  reVal="未结算";
	  }
	   return reVal;
   }
  
  function formatterperFinishStatus(value,row,index){
	  var reVal;
	  if(value=='nofinish'){
		  reVal="未完成";
	  }else if(value=='finish'){
		  reVal="已完成";
	  }else{
		  reVal="未完成";
	  }
	   return reVal;
   }
  
  function initSelect(){
	  	$('#query_name').combobox({
	          url: '/develop/url/getUrl.do',
	          queryParams: {
	        	'name':'getUserSelectList'
	          },
	          valueField: 'id',
	          textField: 'actual_name',
	          method: 'get'
	        })
	        
	        $('#query_task_status').combobox({
	    		data:taskData,
	            valueField: 'id',
	            textField: 'text',
	            method: 'get'
	         });
	  	
		  	$('#query_count_status').combobox({
				data:countData,
		        valueField: 'id',
		        textField: 'text',
		        method: 'get'
		     });
	  }
</script>
